

const fs = require("fs");

const { join } = require("path");

const chalk = require("chalk");

class Animal {
    constructor() {
        this.timer = null;
        this.currentTime = +new Date();
        this.animalList = [];
    }

    init() {
        this.getAnimalList();
        this.draw();
    }

    getAnimalList() {
        const result = fs.readFileSync(join(__dirname, "../animal.txt"), "utf-8");
        this.animalList = result.split("===============++++SEPERATOR++++====================");
    }

    randomColor() {
        return "#" + Math.floor(Math.random() * 11111111).toString(16);
    }

    randomIndex() {
        return Math.floor(Math.random() * (this.animalList.length - 1));
    }
    draw() {

        this.timer = setInterval(() => {
            console.log(chalk.hex(this.randomColor())(this.animalList[this.randomIndex()]));
        }, 500)
    }

};


module.exports = new Animal();